package icu.twtool.database.model

import icu.twtool.database.DatabaseUtil
import java.time.LocalDateTime

/**
 * 练习记录类
 *
 * @param id 自增ID
 * @param exerciseId 习题记录ID
 * @param rightCount 正确题数
 * @param practiceTime 练习时间
 * @author Wen
 * @since 2022-11-05
 */
data class PracticeRecord(
    val id: Int,
    val exerciseId: Int,
    val rightCount: Int,
    val practiceTime: LocalDateTime,
    val practiceFile: String
) {

    companion object {

        fun init() {
            DatabaseUtil.connection {
                createStatement().execute("""
                    create table if not exists TB_PRACTICE_RECORD
                    (
                        ID            int primary key auto_increment comment '属性',
                        EXERCISE_ID   int         not null comment '习题序号',
                        RIGHT_COUNT   int         not null comment '正确数',
                        PRACTICE_FILE varchar(21) not null comment '真实文件名',
                        PRACTICE_TIME datetime default current_timestamp comment '练习时间'
                    );
                """.trimIndent())
            }
        }
    }
}
